<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Fiddle::MemoryView - fiddle: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-export">::export</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-byte_size">#byte_size</a>
    <li ><a href="#method-i-format">#format</a>
    <li ><a href="#method-i-item_size">#item_size</a>
    <li ><a href="#method-i-ndim">#ndim</a>
    <li ><a href="#method-i-obj">#obj</a>
    <li ><a href="#method-i-readonly-3F">#readonly?</a>
    <li ><a href="#method-i-release">#release</a>
    <li ><a href="#method-i-shape">#shape</a>
    <li ><a href="#method-i-strides">#strides</a>
    <li ><a href="#method-i-sub_offsets">#sub_offsets</a>
    <li ><a href="#method-i-to_s">#to_s</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Fiddle::MemoryView">
    <h1 id="class-Fiddle::MemoryView" class="class">
      class Fiddle::MemoryView
    </h1>

    <section class="description">
    
    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-export" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">export</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="export-source">
            <pre>static VALUE
rb_fiddle_memview_s_export(VALUE klass, VALUE target)
{
    ID id_new;
    CONST_ID(id_new, &quot;new&quot;);
    VALUE memview = rb_funcall(klass, id_new, 1, target);
    return rb_ensure(rb_yield, memview, rb_fiddle_memview_release, memview);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
rb_fiddle_memview_initialize(VALUE obj, VALUE target)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (!rb_memory_view_get(target, &amp;data-&gt;view, 0)) {
        data-&gt;view.obj = Qnil;
        rb_raise(rb_eArgError, &quot;Unable to get a memory view from %+&quot;PRIsVALUE, target);
    }

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-5B-5D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">[]</span><span
                                class="method-args">(*args)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="5B-5D-source">
            <pre>static VALUE
rb_fiddle_memview_aref(int argc, VALUE *argv, VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;

    const ssize_t ndim = data-&gt;view.ndim;
    if (argc != ndim) {
        rb_raise(rb_eIndexError, &quot;wrong number of index (%d for %&quot;PRIdSIZE&quot;)&quot;, argc, ndim);
    }

    VALUE indices_v = 0;
    ssize_t *indices = ALLOCV_N(ssize_t, indices_v, ndim);

    ssize_t i;
    for (i = 0; i &lt; ndim; ++i) {
        ssize_t x = NUM2SSIZET(argv[i]);
        indices[i] = x;
    }

    uint8_t *ptr = rb_memory_view_get_item_pointer(&amp;data-&gt;view, indices);
    ALLOCV_END(indices_v);

    if (data-&gt;view.format == NULL) {
        return INT2FIX(*ptr);
    }

    if (!data-&gt;members) {
        const char *err;
        if (rb_memory_view_parse_item_format(data-&gt;view.format, &amp;data-&gt;members, &amp;data-&gt;n_members, &amp;err) &lt; 0) {
            rb_raise(rb_eRuntimeError, &quot;Unable to recognize item format at %&quot;PRIdSIZE&quot; in \&quot;%s\&quot;&quot;,
                     err - data-&gt;view.format, data-&gt;view.format);
        }
    }

    return rb_memory_view_extract_item_members(ptr, data-&gt;members, data-&gt;n_members);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-byte_size" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">byte_size</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="byte_size-source">
            <pre>static VALUE
rb_fiddle_memview_get_byte_size(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    return SSIZET2NUM(data-&gt;view.byte_size);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-format" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">format</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="format-source">
            <pre>static VALUE
rb_fiddle_memview_get_format(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    return data-&gt;view.format == NULL ? Qnil : rb_str_new_cstr(data-&gt;view.format);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-item_size" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">item_size</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="item_size-source">
            <pre>static VALUE
rb_fiddle_memview_get_item_size(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    return SSIZET2NUM(data-&gt;view.item_size);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ndim" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">ndim</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="ndim-source">
            <pre>static VALUE
rb_fiddle_memview_get_ndim(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    return SSIZET2NUM(data-&gt;view.ndim);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-obj" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">obj</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="obj-source">
            <pre>static VALUE
rb_fiddle_memview_get_obj(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    return data-&gt;view.obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-readonly-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">readonly?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="readonly-3F-source">
            <pre>static VALUE
rb_fiddle_memview_get_readonly(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    return data-&gt;view.readonly ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-release" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">release</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="release-source">
            <pre>static VALUE
rb_fiddle_memview_release(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    fiddle_memview_release(data);
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-shape" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">shape</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="shape-source">
            <pre>static VALUE
rb_fiddle_memview_get_shape(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    if (data-&gt;view.shape == NULL) return Qnil;

    const ssize_t ndim = data-&gt;view.ndim;
    VALUE shape = rb_ary_new_capa(ndim);
    ssize_t i;
    for (i = 0; i &lt; ndim; ++i) {
        rb_ary_push(shape, SSIZET2NUM(data-&gt;view.shape[i]));
    }
    return shape;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-strides" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">strides</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="strides-source">
            <pre>static VALUE
rb_fiddle_memview_get_strides(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    if (data-&gt;view.strides == NULL) return Qnil;

    const ssize_t ndim = data-&gt;view.ndim;
    VALUE strides = rb_ary_new_capa(ndim);
    ssize_t i;
    for (i = 0; i &lt; ndim; ++i) {
        rb_ary_push(strides, SSIZET2NUM(data-&gt;view.strides[i]));
    }
    return strides;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sub_offsets" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">sub_offsets</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="sub_offsets-source">
            <pre>static VALUE
rb_fiddle_memview_get_sub_offsets(VALUE obj)
{
    struct memview_data *data;
    TypedData_Get_Struct(obj, struct memview_data, &amp;fiddle_memview_data_type, data);

    if (NIL_P(data-&gt;view.obj)) return Qnil;
    if (data-&gt;view.sub_offsets == NULL) return Qnil;

    const ssize_t ndim = data-&gt;view.ndim;
    VALUE sub_offsets = rb_ary_new_capa(ndim);
    ssize_t i;
    for (i = 0; i &lt; ndim; ++i) {
        rb_ary_push(sub_offsets, SSIZET2NUM(data-&gt;view.sub_offsets[i]));
    }
    return sub_offsets;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">to_s</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="to_s-source">
            <pre>static VALUE
rb_fiddle_memview_to_s(VALUE self)
{
    struct memview_data *data;
    const char *raw_data;
    long byte_size;
    VALUE string;

    TypedData_Get_Struct(self,
                         struct memview_data,
                         &amp;fiddle_memview_data_type,
                         data);

    if (NIL_P(data-&gt;view.obj)) {
        raw_data = NULL;
        byte_size = 0;
    } else {
        raw_data = data-&gt;view.data;
        byte_size = data-&gt;view.byte_size;
    }

    string = rb_enc_str_new_static(raw_data, byte_size, rb_ascii8bit_encoding());
    {
        ID id_memory_view;
        CONST_ID(id_memory_view, &quot;memory_view&quot;);
        rb_ivar_set(string, id_memory_view, self);
    }
    return rb_obj_freeze(string);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

